package api.my_api;

import java.util.Arrays;
import java.util.Objects;

public class Test {
    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5};
        int[] newArr = new int[6];
        System.arraycopy(arr, 0, newArr, 0,Math.min(arr.length,newArr.length));
        System.out.println(Arrays.toString(newArr));
        A a = new A(1);
        A a2 = new A(2);
        System.out.println(a.equals(a2));
        System.out.println(a);
        System.out.println(a2);
        System.out.println(a.hashCode() == a2.hashCode());
        System.out.println(Objects.toString(a, "对象为null"));
        System.out.println(Objects.equals(a,a2));
        System.out.println("================================");
        A nonNull = Objects.requireNonNull(a);
        System.out.println(nonNull);
        A requireNonNullElse = Objects.requireNonNullElse(a, a2);
        System.out.println(requireNonNullElse);
        Objects.requireNonNullElseGet(a,A::new);


    }
}
class A{
    private int num;

    // 哈希值和真实的物理地址是不一样的
    @Override
    public int hashCode() {
        return Objects.hash(num);
    }


    public A() {
    }

    public A(int num) {
        this.num = num;
    }

    /**
     * 获取
     * @return num
     */
    public int getNum() {
        return num;
    }

    /**
     * 设置
     * @param num
     */
    public void setNum(int num) {
        this.num = num;
    }


    public String toString() {
        return "A{num = " + num + "}";
    }
}